# dwm - dynamic window manager
# See LICENSE file for copyright and license details.
make_dir:=$(shell pwd)   # := 的意思是将$(shell pwd) 表示为make_dir，类似于宏定义
home_dir:=$(shell echo ${HOME})   # 此种方法下 sudo 下，Fefora Archlinux 获得的是/root
user_dir:=$(shell echo ${USER})   # 此种方法下 sudo 下，Fefora Archlinux 获得的是 root

include config.mk

SRC = drw.c dwm.c util.c
OBJ = ${SRC:.c=.o}

all: options dwm

options:
	@echo dwm build options:
	@echo "CFLAGS   = ${CFLAGS}"
	@echo "LDFLAGS  = ${LDFLAGS}"
	@echo "CC       = ${CC}"

.c.o:
	${CC} -c ${CFLAGS} $<

${OBJ}: config.h config.mk

config.h:
	cp config.def.h $@

dwm: ${OBJ}
	${CC} -o $@ ${OBJ} ${LDFLAGS}

clean:
	rm -f dwm ${OBJ} dwm-${VERSION}.tar.gz  config.h 

dist: clean
	mkdir -p dwm-${VERSION}
	cp -R LICENSE Makefile README config.def.h config.mk\
		dwm.1 drw.h util.h ${SRC} dwm.png transient.c dwm-${VERSION}
	tar -cf dwm-${VERSION}.tar dwm-${VERSION}
	gzip dwm-${VERSION}.tar
	rm -rf dwm-${VERSION} config.h

install: all
	mkdir -p ${DESTDIR}${PREFIX}/bin
	cp -f dwm ${DESTDIR}${PREFIX}/bin
	chmod 755 ${DESTDIR}${PREFIX}/bin/dwm
	mkdir -p ${DESTDIR}${MANPREFIX}/man1
	sed "s/VERSION/${VERSION}/g" < dwm.1 > ${DESTDIR}${MANPREFIX}/man1/dwm.1
	chmod 644 ${DESTDIR}${MANPREFIX}/man1/dwm.1
	cp ./DWM.desktop  /usr/share/xsessions
	chmod 755 /usr/share/xsessions/DWM.desktop
# 	rm -rf ${HOME}/.dwm
# 	cp -r ./scripts ${HOME}/.dwm/

dev: all
# 	mkdir -p ${DESTDIR}${PREFIX}/bin
# 	cp -f dwm ${DESTDIR}${PREFIX}/bin
# 	chmod 755 ${DESTDIR}${PREFIX}/bin/dwm
# 	mkdir -p ${DESTDIR}${MANPREFIX}/man1
# 	sed "s/VERSION/${VERSION}/g" < dwm.1 > ${DESTDIR}${MANPREFIX}/man1/dwm.1
# 	chmod 644 ${DESTDIR}${MANPREFIX}/man1/dwm.1
# 	cp ./DWM.desktop  /usr/share/xsessions
# 	chmod 755 /usr/share/xsessions/DWM.desktop
# 	/bin/sh ./ln.sh 
	echo make_dir is $(make_dir)
	echo home_dir is ${home_dir}
	echo user_dir is ${user_dir}
	echo HOME is ${HOME}

uninstall:
	rm -f ${DESTDIR}${PREFIX}/bin/dwm\
		${DESTDIR}${MANPREFIX}/man1/dwm.1\
		/usr/share/xsessions/DWM.desktop \

.PHONY: all options clean dist install uninstall

# [Makefile 中获取自身目录（pwd, lastword,dirname）_while_false_的博客-CSDN博客_makefile pwd](https://blog.csdn.net/qq_34595352/article/details/102954664)
# [Linux 下 sudo $HOME 改变问题解决 - akiyaの博客](https://little-star.love/posts/d3a9d9ff/)
# [如何获取Makefile中的用户名？ 中国服务器网](https://zgserver.com/makefile-26.html)

